//
//  IdCardSuccessViewController.m
//  DanaKreditLoan
//
//  Created by ZhengChengFeng on 2024/10/21.
//

#import "IdCardSuccessViewController.h"
#import "OrderDetailModel.h"

#import "PersonInfoViewController.h"
#import "ContactInfoViewController.h"
#import "BankCardInfoViewController.h"

#define kFootViewHeight  (15 + 48 + (IS_IPhoneX_All ? kHeight_BottomSafe : 15))

@interface IdCardSuccessViewController ()

@property (nonatomic) OrderDetailModel *orderDetModel;

@end

@implementation IdCardSuccessViewController

- (void)back{
    [[self getCurrentVC] jumpToPopControlClass:@"OrderDetailViewController"];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)initFootView{

    UIView *bottomV = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - kFootViewHeight - kNavigationBarHeight, kScreenWidth, kFootViewHeight)];
    bottomV.backgroundColor = kTableViewBackColor;
    [self.view addSubview:bottomV];
    
    
    UIButton *nextBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 15, kScreenWidth - 30, 48)];
    nextBtn.titleLabel.font = [UIFont fontWithName:kFuturaMedium size:16];
    [nextBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [nextBtn setTitleColor:kWhiteColor forState:UIControlStateSelected];
    [nextBtn setTitleColor:kWhiteColor forState:UIControlStateHighlighted];
    [nextBtn setTitle:ASLocalizedString(@"OK") forState:UIControlStateNormal];
    [nextBtn setTitle:ASLocalizedString(@"OK") forState:UIControlStateSelected];
    [nextBtn setTitle:ASLocalizedString(@"OK") forState:UIControlStateHighlighted];
    [nextBtn setImage:[UIImage imageNamed:@"icon_login2"] forState:UIControlStateNormal];
    [nextBtn setImage:[UIImage imageNamed:@"icon_login2"] forState:UIControlStateSelected];
    [nextBtn setImage:[UIImage imageNamed:@"icon_login2"] forState:UIControlStateHighlighted];
    [nextBtn addTarget:self action:@selector(enterNextPage) forControlEvents:UIControlEventTouchUpInside];
    nextBtn.backgroundColor = kButtonDefaultColor;
    nextBtn.layer.cornerRadius = 24;
    nextBtn.layer.masksToBounds = YES;
    [bottomV addSubview:nextBtn];
    [nextBtn setImgRightTitltLeft:10];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kFootViewHeight );
    
    [self initFootView];
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 64 + 164 + 58 + 30 + 73 + 12 + 73 + 12 + 73 + 12)];
    self.tableView.tableHeaderView = headView;
    
    UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth - 167)/2, 64, 167, 164)];
    imgV.image = [UIImage imageNamed:@"icon_idcard14"];
    [headView addSubview:imgV];
    
    UILabel *lab1 = [UILabel createLabel:[UIFont fontWithName:kFuturaBold size:15] color:kBlackColor];
    lab1.frame = CGRectMake(0, imgV.bottom, kScreenWidth, 32);
    lab1.textAlignment = 1;
    [headView addSubview:lab1];
    lab1.text = ASLocalizedString(@"AuthenticationStr1");
    
    UILabel *lab2 = [UILabel createLabel:[UIFont fontWithName:kFutura size:13] color:kBlackColor];
    lab2.frame = CGRectMake(0, lab1.bottom, kScreenWidth, 28);
    lab2.textAlignment = 1;
    [headView addSubview:lab2];
    lab2.text = ASLocalizedString(@"AuthenticationStr2");
    
    
    UIView *nameV = [[UIView alloc] initWithFrame:CGRectMake(30, lab2.bottom + 20, kScreenWidth - 60, 73)];
    nameV.backgroundColor = [UIColor whiteColor];
    [headView addSubview:nameV];
    nameV.layer.cornerRadius = 14;
    nameV.layer.masksToBounds = YES;
    nameV.layer.borderColor = [UIColor colorWithHexString:@"#EFEFEF"].CGColor;
    nameV.layer.borderWidth = 1;
    
    UILabel *labName = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:[UIColor colorWithHexString:@"#6C6C6C"]];
    labName.text = ASLocalizedString(@"Aadhaar Name");
    [nameV addSubview:labName];
    labName.frame = CGRectMake(15, 10, 200, 20);
    
    UILabel *fullNameValueLab = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kButtonDefaultColor];
    [nameV addSubview:fullNameValueLab];
    fullNameValueLab.frame = CGRectMake(15, labName.bottom + 3, nameV.width - 30, 40);
    fullNameValueLab.text = esString(self.nameStr);
    
    
    UIView *numberV = [[UIView alloc] initWithFrame:CGRectMake(nameV.left,nameV.bottom + 12, nameV.width ,nameV.height)];
    numberV.backgroundColor = [UIColor whiteColor];
    [headView addSubview:numberV];
    numberV.layer.cornerRadius = 14;
    numberV.layer.masksToBounds = YES;
    numberV.layer.borderColor = [UIColor colorWithHexString:@"#EFEFEF"].CGColor;
    numberV.layer.borderWidth = 1;
    
    UILabel *labNumber = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:[UIColor colorWithHexString:@"#6C6C6C"]];
    labNumber.text = ASLocalizedString(@"Aadhaar Number");
    [numberV addSubview:labNumber];
    labNumber.frame = CGRectMake(15, 10, 200, 20);
    
    UILabel *IDNoValueLab = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kButtonDefaultColor];
    [numberV addSubview:IDNoValueLab];
    IDNoValueLab.text = esString(self.idNoStr);
    IDNoValueLab.frame = CGRectMake(15, labNumber.bottom + 3, nameV.width - 30, 40);
    
    
    
    UIView *dateV = [[UIView alloc] initWithFrame:CGRectMake(nameV.left,numberV.bottom + 12, nameV.width ,nameV.height)];
    dateV.backgroundColor = [UIColor whiteColor];
    [headView addSubview:dateV];
    dateV.layer.cornerRadius = 14;
    dateV.layer.masksToBounds = YES;
    dateV.layer.borderColor = [UIColor colorWithHexString:@"#EFEFEF"].CGColor;
    dateV.layer.borderWidth = 1;
    
    UILabel *labDate = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:[UIColor colorWithHexString:@"#6C6C6C"]];
    labDate.text = ASLocalizedString(@"Birthday");
    [dateV addSubview:labDate];
    labDate.frame = CGRectMake(15, 10, 200, 20);
    
    UILabel *DateValueLab = [UILabel createLabel:[UIFont fontWithName:kFutura size:14] color:kButtonDefaultColor];
    [dateV addSubview:DateValueLab];
    DateValueLab.text = esString(self.birDateStr);
    DateValueLab.frame = CGRectMake(15, labDate.bottom + 3, nameV.width - 30, 40);
    
    fullNameValueLab.text = esString(self.nameStr);
    IDNoValueLab.text = esString(self.idNoStr);
    DateValueLab.text = esString(self.birDateStr);
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)enterNextPage{
    
    [BoxLoadingHelper showBoxLoadingWithMessage:@""];
    NSMutableDictionary *muDic = @{
        @"largely":esString(self.idStr),
        @"mainland":@"mainlandOrderDet",
    }.mutableCopy;
    [HttpNetHelper postNetworkHelperForPath:kOrderDetailUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
        [BoxLoadingHelper hideBoxLoading];
        [BoxLoadingHelper hideBoxLoadingFromView:self.view];
        if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
            [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
            return;
        }
    
      
        NSDictionary *dic = responseDic[@"clip"];
       
        OrderDetailModel *model = [OrderDetailModel mj_objectWithKeyValues:dic];
        self.orderDetModel = model;
        
        if (PMObjectIsEmpty(model.swears)) {
            [self enterOrderH5Page];
            return;
        }
        if ([esString(model.swears.undiluted) isEqualToString:kPersonInfoVertify]) {
            [self goPersonalVertify];
        }
        else if ([esString(model.swears.undiluted) isEqualToString:kContactInfoVertify]) {
            [self goContactVertify];
        }
        else if ([esString(model.swears.undiluted) isEqualToString:kBankInfoVertify]) {
            [self goBankVertify];
        }

        
    } onCompleteFailur:^(NSError * _Nonnull error) {
        [BoxLoadingHelper hideBoxLoading];
        [BoxLoadingHelper hideBoxLoadingFromView:self.view];
    } withIsForm:YES];
    

}
    

- (void)enterOrderH5Page{
        NSMutableDictionary *muDic = @{
            @"dosed":esString(self.orderDetModel.refugees.passages),
            @"founders":esString(self.orderDetModel.refugees.founders),
            @"weakness":esString(self.orderDetModel.refugees.weakness),
            @"shouldered":esString(self.orderDetModel.refugees.shouldered),
            @"guiding":@"guidingIdStr",
            @"excuse":@"excuseIdStr",
        }.mutableCopy;
        
        [BoxLoadingHelper showBoxLoadingWithMessage:@""];
        [HttpNetHelper postNetworkHelperForPath:kOrderNoUrl parameter:muDic onCompleteSuccess:^(NSDictionary * _Nonnull responseDic) {
            [BoxLoadingHelper hideBoxLoading];
            if ([responseDic[@"pineapples"] integerValue] != kSuccessCode) {
                [BoxLoadingHelper showBoxWithMessage:esString(responseDic[@"shin"])];
                return;
            }
        
            NSDictionary *dic = responseDic[@"clip"];
            
            [[DKCore sharedDKCore] jumpToControllerWithUrlString:esString(dic[@"twentieth"])];
          
        } onCompleteFailur:^(NSError * _Nonnull error) {
            [BoxLoadingHelper hideBoxLoading];
        } withIsForm:YES];
        
}


- (void)goPersonalVertify{
    PersonInfoViewController *vc = [[PersonInfoViewController alloc] init];
    vc.idStr = esString(self.idStr);
    vc.orderNoStr = esString(self.orderNoStr);
    vc.title = esString(self.orderDetModel.swears.arrow);
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)goContactVertify{
    ContactInfoViewController *vc = [[ContactInfoViewController alloc] init];
    vc.idStr = esString(self.idStr);
    vc.orderNoStr = esString(self.orderNoStr);
    vc.title = esString(self.orderDetModel.swears.arrow);
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)goBankVertify{
    BankCardInfoViewController *vc = [[BankCardInfoViewController alloc] init];
    vc.idStr = esString(self.idStr);
    vc.orderNoStr = esString(self.orderNoStr);
    vc.title = esString(self.orderDetModel.swears.arrow);
    [self.navigationController pushViewController:vc animated:YES];
}


@end
